<template>
    <div class="newinfo-container">
        <!-- <h3>{{ $router.params.id }}</h3> -->
        <!-- 新闻主标题 -->
        <h3 class="title">{{ newinfo.title }}</h3>
        <!-- 子标题部分 -->
        <p class="subtitle">
            <span>发表时间：{{ newinfo.add_time | dateFormat }}</span>
            <span>点击： {{ newinfo.click }}次</span>
        </p>
        <hr>
        <!-- 主体内容 -->
        <div class="content" v-html="newinfo.content"></div>
        <!-- 评论区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>
<script>
    // 导入评论子组件
    import comment from '../subcomponents/Comment.vue';

    import { Toast } from 'mint-ui';
    export default {
        data(){
            return {
                id: $router.params.id,  //将url传递过来的ID挂载到到data上
                newinfo: {} //新闻对象
            }
        },
        methods:{
            created() {
                this.getNewsInfo();
            },
            // 获取新闻详情
            getNewsInfo(){
                this.$http.get('api/getnew/' +  this.id).then( result => {
                    if(result.body.status == 0){
                        this.newinfo = result.body.message;
                    }else{
                        Toast('获取新闻详情失败');
                    }
                });
            }
        },
        components:{//注册子组件
            'comment-box': comment
        }   
    }
</script>
<style lang="scss">
    .newinfo-container{
        padding: 0 4px;
        .title{
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: red;
        }
        .subtitle{
            font-size: 13px;
            color: #226aff;
            display: flex;
            justify-content: space-between;
        }
        .content{
            img{
                width: 100%;
                height: 100%;
            }
        }
    }
</style>